package routines

import (
	"fmt"
)

func sum(vals []int, resultChan chan int) {
	sum := 0

	for _, v := range vals {
		sum += v
	}
	// 将计算结果发送到channel中。
	resultChan <- sum
}

func Calual() {
	values := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

	resultChan := make(chan int, 2)

	go sum(values[:len(values)/2], resultChan)
	go sum(values[len(values)/2:], resultChan)
	sum1, sum2 := <-resultChan, <-resultChan
	fmt.Println("Result:", sum1, sum2)
}
